package com.uni.utils;

import java.beans.PropertyEditorSupport;

import com.uni.db.GenericService;
import com.uni.domain.Identifiable;


//TODO: remove this class from this package.   
public class CreatorFromId<T extends Identifiable> extends PropertyEditorSupport {
    //TODO: Hm.. Probably, it must initialize in some another way.
    private GenericService<T> service;


    public CreatorFromId(GenericService<T> service) {
        this.service = service;
    }

    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        setValue(getById(Long.parseLong(text)));
    }

    public T getById(Long id){
        return service.get(id);
    }
}
